home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / 3DLIB25.ZIP / RTOBJ.INT < prev    next >
Text File  |  1993-12-26  |  8KB  |  192 lines

  1. (******************************************************************************
  2. *                                    rtObj                                    *
  3. *      please notice -                                                        *
  4. *      this unit includes both the object3d unit, and the superobj unit,      *
  5. *      and it is used with no reference to the WWToolKit window GUI library,  *
  6. *      uses project3, instead of prjWind  (It does, however, support OWL)     *
  7. *                                                                             *
  8. * In V2.x - The support collections are part of this unit as well ...         *
  9. ******************************************************************************)
  10. Unit rtObj;
  11.  
  12. (*******************************************************************************
  13. *                                 3D Objects                                   *
  14. *                                 ----------                                   *
  15. *                                                                              *
  16. *   A 3D object is a collection of points and lines in the 3D universe,        *
  17. *   that represent the body we want to draw on the screen.                     *
  18. *   A 3D object is allways centered around point (0, 0, 0) in the 3D universe. *
  19. *   (Its center of gravity assuming it is has a uniform weight distribution    *
  20. *    is in point (0, 0, 0)                                                     *
  21. *   At any moment during the object's life, we know it's distance from the     *
  22. *   origin, And it's rotation using reveres rotation CTM.                      *
  23. *                                                                              *
  24. *   3D Object methods:                                                         *
  25. *      constructor Open                                                        *
  26. *      destructor  CloseMe                                                     *
  27. *      procedures: Rotate, Scale, Move, Show, Hide, Load, Save                 *
  28. *                  SetToOrigin, Paint                                          *
  29. *                                                                              *
  30. *******************************************************************************)
  31.  
  32. interface
  33.  
  34. uses
  35. {$ifdef windows}
  36.     winTypes
  37.     ,winProcs
  38. {$else}
  39.     graph
  40. {$endif}
  41.     ,Ctm3d
  42.     ,hdr3d
  43.     ,project3
  44.     ,objects { needed for collection support .. }
  45.     ;
  46.  
  47. type
  48.    P3dPointCollection = ^ T3dPointCollection;
  49.    T3dPointCollection = object(TCollection)
  50.  
  51.       procedure freeItem(item : pointer); virtual;
  52.  
  53.    end; { T3dPointCollection definition .. }
  54.  
  55.    P3dLineCollection = ^ T3dLineCollection;
  56.    T3dLineCollection = object(TCollection)
  57.  
  58.       procedure freeItem(item : pointer); virtual;
  59.  
  60.    end; { T3dLineCollection definition .. }
  61.  
  62.    PScreenPointsCollection = ^ TScreenPointsCollection;
  63.    TScreenPointsCollection = object(TCollection)
  64.  
  65.       procedure freeItem(item : pointer); virtual;
  66.  
  67.    end; { TScreenPointsCollection definition .. }
  68.  
  69. type
  70.     f_real = file of real;
  71.  
  72.     {===================================================================}
  73.     {  Base object is the base class for 3D-objects. some functions     }
  74.     { are dummy virtual do-nothing, which are are implemented only for  }
  75.     { the descendend objects derived from BaseObject                    }
  76.     {===================================================================}
  77.  
  78.     BaseObjectPtr = ^BaseObject;
  79.     BaseObject = object
  80.        MyCtm       : Ctm;      { This CTM applied to the object gives the  }
  81.                                {  objects Position after transformations   }
  82.        Name        : String;   { Identifies the object                     }
  83.        myColor     : word;     { Main color for the object                 }
  84.        Location    : point3d;  { Central of gravity in real space          }
  85.        scrPntUpdt  : boolean;  { True if screen points updated             }
  86.  
  87.        constructor open(myName : string; color : word);
  88.        destructor  CloseMe; virtual;
  89. {$ifdef windows}
  90.        procedure   show(dc : hdc); virtual;
  91.        procedure   hide(dc : hdc); virtual;
  92.        procedure   paint(dc : hdc); virtual; {in specified color}
  93. {$else}
  94.        procedure   show; virtual;
  95.        procedure   hide; virtual;
  96.        procedure   paint; virtual; {in specified color}
  97. {$endif}
  98.        procedure   updateScreenPoints; virtual; {transform object 3D -> 2D}
  99.        procedure   move(axis : axisType; by : real); virtual;
  100.        procedure   translate(dx, dy, dz : integer); virtual;
  101.                {multy dimentional move in 1 call}
  102.        procedure   scale(axis : axisType; factor : real); virtual;
  103.        procedure   allScale(sx, sy, sz : real); virtual;
  104.                {multy dimentional scale in 1 call}
  105.        procedure   rotate(axis : axisType; deg : real); virtual;
  106.  
  107.        procedure   goto3dPos(x, y, z : real); virtual; {translate to absolute place}
  108.        procedure   setToOrigin; virtual;
  109.                {translate to 0,0,0, update points, and set myCtm to unit}
  110.        procedure   calcLocation; virtual; {set Location to central gravity}
  111.        procedure   deleteTransform; virtual; {set MyCtm to unit}
  112.  
  113.        function load : word; virtual; {from disk}
  114.        function save : word; virtual; {to   disk}
  115.        procedure writeMe(var elementFile : f_real); virtual; {to disk .. without opening file..}
  116.        procedure readMe(var elementFile : f_real); virtual;
  117.     end;
  118.  
  119.     {===================================================================}
  120.     { Obj3d is an object which represents a 3-D object with a poligon  }
  121.     {  mesh.                                                           }
  122.     {===================================================================}
  123.  
  124.     Obj3dPtr = ^Obj3d;
  125.     Obj3d = object(BaseObject)
  126. (*       Points      : array[1..MaxPoints] of point3d; *)
  127.        Points      : T3dPointCollection; 
  128. (*       Lines       : array[1..MaxLines]   of Line3d; *)
  129.        Lines       : T3dLineCollection;
  130. (*       scrPoints   : array[1..MaxPoints] of screenPoints; *)
  131.        scrPoints   : TScreenPointsCollection;
  132.        NumOfLines  : integer;
  133.        NumOfPoints : integer;
  134.        ReverseRot  : Ctm;  { Saves only the reverse rotations }
  135.        unReverseRot: Ctm;  { reverse of the above}
  136.  
  137.        constructor open(myName : string; ref : point3d; color : word);
  138.        destructor  CloseMe; virtual;
  139. {$ifdef windows}
  140.        procedure   paint(dc : hdc); virtual; {in specified color}
  141. {$else}
  142.        procedure   paint; virtual; {in specified color}
  143. {$endif}
  144.        procedure   updateScreenPoints; virtual; {transform object 3D -> 2D}
  145.  
  146.        procedure   calcLocation; virtual; {set Location to central gravity}
  147.        procedure   setToOrigin; virtual;
  148.  
  149.        procedure writeMe(var elementFile : f_real); virtual;
  150.        procedure readMe(var elementFile : f_real); virtual;
  151.     end;
  152.  
  153. const
  154.    maxSubObjects = 15;
  155.  
  156. type
  157.     complexObjPtr = ^complexObj;
  158.     ComplexObj = object(BaseObject)
  159.        childs      : array [1..maxSubObjects] of obj3dPtr;
  160.        ctms        : array [1..maxSubObjects] of ctm;
  161.        numOfChilds : integer; {counter of # of obj3d childs}
  162.  
  163.        constructor open(myName : string; color : word);
  164.        destructor  closeMe; virtual;
  165.        procedure   updateScreenPoints; virtual;
  166.        procedure   writeMe(var elementFile : f_real); virtual;
  167.        procedure   readMe(var elementFile : f_real); virtual;
  168.        procedure   calcLocation; virtual;
  169. {$ifdef WINDOWS}
  170.        procedure   paint(dc : hdc); virtual;
  171. {$else}
  172.        procedure   paint; virtual;
  173. {$endif}
  174.        procedure   move(axis : axisType; by : real); virtual;
  175.        procedure   rotate(axis : axisType; deg : real); virtual;
  176.        procedure   scale(axis : axisType; factor : real); virtual;
  177.  
  178.        function    addSubObject(myName : string; refPoint : point3d) : word;
  179.        function    getChildPtr(index : integer) : obj3dPtr;
  180.        procedure   rotateChild(child : integer; axis : axisType;
  181.